package com.itheima.backstage.manager;

import com.itheima.service.mongo.UserLocationService;
import org.apache.dubbo.config.annotation.Reference;
import org.springframework.stereotype.Component;


import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;

@Component
public class HouTaoManager {
    @Reference
    private UserLocationService userLocationService;
    //根据用户id获取用户位置的坐标值
    public List<Double> findBaiDuMap(String id) {
        List<Double> coordinates = userLocationService.findBaiDuMap(id);
        ArrayList arrayList = new ArrayList();
        Double x = double2Str(coordinates.get(0));
        Double y = double2Str(coordinates.get(1));
        arrayList.add(x);
        arrayList.add(y);
        return arrayList;

    }

    /**
     * 格式化double结果，这样转换成字符串就不会采用科学计数法。
     * @param d
     * @return
     */
    public Double double2Str(Double d) {
        BigDecimal bd = new BigDecimal(d);
        String s1 = bd.toString();
        String substring = s1.substring(0, 11);
        return Double.valueOf(substring);
    }
}
